/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package APP3.services;

import APP3.bookshop.book.ABook;
import APP3.bookshop.main.BookShop;
import APP3.bookshop.person.publisher.Publisher;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;

/**
 *
 * @author Asus
 */
public class PublisherService {

    private BookShop bookShop;

    public PublisherService(BookShop bookShop) {
        this.bookShop = bookShop;
    }

    public DefaultListModel populatePublisherList() {
        DefaultListModel pubList = new DefaultListModel();
        for (Publisher publisher : bookShop.getPublishers()) {
            pubList.addElement(publisher);

        }

        return pubList;
    }
    
        public DefaultComboBoxModel populatePublisherComboBox() {
         DefaultComboBoxModel  pubList = new DefaultComboBoxModel();
        for (Publisher publisher : bookShop.getPublishers()) {
            pubList.addElement(publisher);

        }

        return pubList;
    }
    

    public DefaultListModel populatePublisherBooksList(Publisher pub) {
        DefaultListModel pubbookList = new DefaultListModel();
        for (ABook book : pub.getaBook()) {
            pubbookList.addElement(book);

        }

        return pubbookList;
    }

    public String addPublisher(String name, String email, String phone, String postalCode) {
        if (name.equals("") && email.equals("") && phone.equals("") && postalCode.equals("")) {
            return "Input ERROR";
        }

        Publisher p = new Publisher();
        p.setName(name);
        p.setEmail(email);
        p.setPostalCode(postalCode);
        p.setPhoneNumber(phone);

        bookShop.getPublishers().add(p);
        return "SAVED";
    }

}
